package com.zzp.elasticsearch_demo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;

@Data
@Document(indexName = "user")
@JsonIgnoreProperties(ignoreUnknown = true)
public class User implements Serializable {

    @Id
    private Long id;

    public User() {
    }

    public User(Long id, String username, String address, Long age, Date createTime) {
        this.id = id;
        this.username = username;
        this.address = address;
        this.age = age;
        this.createTime = createTime;
    }

    //  es 中能分词的字段，这个字段数据类型必须是 text！keyword 不分词！ analyzer = "ik_max_word"
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String username;

    @Field(type = FieldType.Keyword)
    private String address;

    @Field(type = FieldType.Long)
    private Long age;

    @Field(type = FieldType.Date,format = DateFormat.date_time, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
}